package com.yimi.policyservice.repository;

import com.yimi.policyservice.entity.base.system.SysPermission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SysPermissionRepository extends JpaRepository<SysPermission,String> {

    /**
     * 获取用户权限
     * @param id
     * @return
     */
    @Query(value = " select * from t_sys_permission where id in ( " +
            "  select rp.permission_id " +
            "  from t_sys_role_permission rp " +
            "  where role_id in (select ru.role_id from t_sys_user_role ru where ru.user_id = ?1) " +
            " )" ,nativeQuery = true)
    List<SysPermission> findUserPermisssions(String id);

    List<SysPermission> findByMenuId(String id);
}
